﻿using System;
using System.Data;
using System.Configuration;
using ChinaGS.Lian;
using ChinaGS.Lian.ModuleRemoting;

/// <summary>
///RemotingClass 的摘要说明
/// </summary>
public static class RemotingClass
{

    private static int PORT = 10082;                                                     //端口号
    private static String SERVICENAME = "LianRemotingService";        //服务名称
    private static String IP = "123.234.229.226";                                   //ip地址
    private static String areaNo = "532";                                               //区域号码
    private static String agentNo = "QD000003";                                  //商户号
    private static String clientNo = "QD20003";                                           //终端号
    private static String keyCode = "cWfu/fR9dU/0dBA9ICKpBTlKnofxLHSw";                  //授权KEY    
    private static String PersonNo = "1000";                                         //员工号

   /* private static int PORT = 10082;                                                     //端口号
    private static String SERVICENAME = "LianRemotingService";        //服务名称
    private static String IP = "123.123.123.123";                                   //ip地址
    private static String areaNo="532";                                               //区域号码
    private static String agentNo="QD000001";                                  //商户号
    private static String clientNo="qd01";                                           //终端号
    private static String keyCode="XXXXXXXXXXXYYYYY";                  //授权KEY    
    private static String PersonNo = "911";                                         //员工号*/

    //中国移动用户账单查询
    public static MobilePackage mobileBillCheck(String cusNo)
    {
        IMobileModule imm = (IMobileModule)ModuleFactory.GetModule(ModuleName.Mobile, IP, PORT, SERVICENAME);       
        MobilePackage mp = imm.Query(areaNo, cusNo, agentNo, clientNo, keyCode);
        return mp;       
    }

    //中国移动缴费
    public static MobilePackage mobilePayMoney(String cusNo, String accpetType, double payMoney)
    {
        IMobileModule imm = (IMobileModule)ModuleFactory.GetModule(ModuleName.Mobile, IP, PORT, SERVICENAME);
        MobilePackage mp = imm.Payment(agentNo, cusNo, accpetType, payMoney, agentNo, clientNo, PersonNo, keyCode);
        return mp;
    }   

    //中国移动冲正
    public static MobilePackage mobileBackOut(String cusNo, String serialNo)
    {
        IMobileModule imm = (IMobileModule)ModuleFactory.GetModule(ModuleName.Mobile, IP, PORT, SERVICENAME);
        MobilePackage mp = imm.BackOut(serialNo, areaNo, cusNo, agentNo, clientNo, keyCode);
        return mp;
    }

    //中国电信查询
    public static TeleComPackage teleComBillCheck(String cusNo)
    {
        ITeleComModule itcm = (ITeleComModule)ModuleFactory.GetModule(ModuleName.TeleCom, IP, PORT, SERVICENAME);      
        TeleComPackage tcp = itcm.Query(areaNo, cusNo, agentNo, clientNo, keyCode);        
        return tcp;
    }

    //中国电信缴费
    public static TeleComPackage teleComPayMoney(String acct_id, String cusNo, String accpetType, double payMoney) {       
        ITeleComModule itcm = (ITeleComModule)ModuleFactory.GetModule(ModuleName.TeleCom, IP, PORT, SERVICENAME);
        TeleComPackage tcp = itcm.Payment(acct_id, areaNo, cusNo, accpetType, payMoney, agentNo, clientNo, PersonNo, keyCode);
        return tcp;
    }

    //中国电信冲正
    public static TeleComPackage teleComBackOut(String cusNo, String serialNo)
    {
        ITeleComModule itcm = (ITeleComModule)ModuleFactory.GetModule(ModuleName.TeleCom, IP, PORT, SERVICENAME);
        TeleComPackage tcp = itcm.BackOut(serialNo, areaNo, cusNo, agentNo, clientNo, keyCode);
        return tcp;
    }

    //联通固话查询
    public static NetComPackage netComBillCheck(String cusNo) {
        INetComModule incm = (INetComModule)ModuleFactory.GetModule(ModuleName.NetCom, IP, PORT, SERVICENAME);
        NetComPackage ncp = incm.Query(areaNo, cusNo, agentNo, clientNo, keyCode);
        return ncp;
    }

    //联通固话缴费
    public static NetComPackage netComPayMoney(String acctId, String cusNo, Double payMoney, Double preMoney) {
        INetComModule incm = (INetComModule)ModuleFactory.GetModule(ModuleName.NetCom, IP, PORT, SERVICENAME);
        NetComPackage ncp = incm.Payment(acctId, areaNo, cusNo, payMoney, preMoney, agentNo, clientNo, PersonNo, keyCode);
        return ncp;
    }

    //联通固话冲正
    public static NetComPackage netComBackOut(String cusNo, String serialNo)
    {
        INetComModule incm = (INetComModule)ModuleFactory.GetModule(ModuleName.NetCom, IP, PORT, SERVICENAME);
        NetComPackage ncp = incm.BackOut(serialNo, areaNo, cusNo, agentNo, clientNo, keyCode);
        return ncp;
    }

    //联通G网话费查询
    public static UnicomPackage uniComBillCheck(String cusNo) {
        IUnicomModule iucm = (IUnicomModule)ModuleFactory.GetModule(ModuleName.Unicom, IP, PORT, SERVICENAME);
        UnicomPackage ucp = iucm.Query(cusNo, agentNo, clientNo, keyCode);
        return ucp;
    }

    //联通G网缴费
    public static UnicomPackage uniComPayMoney(String cusNo, String ItemNo, Double payMoney) {
        IUnicomModule iucm = (IUnicomModule)ModuleFactory.GetModule(ModuleName.Unicom, IP, PORT, SERVICENAME);
        UnicomPackage ucp = iucm.Payment(cusNo, ItemNo, payMoney, agentNo, clientNo, PersonNo, keyCode);
        return ucp;
    }

    //联通G网冲正
    public static UnicomPackage uniComBackOut(String cusNo, String serialNo, Double payMoney)
    {
        IUnicomModule iucm = (IUnicomModule)ModuleFactory.GetModule(ModuleName.Unicom, IP, PORT, SERVICENAME);
        UnicomPackage ucp = iucm.BackOut(serialNo, cusNo, payMoney, agentNo, clientNo, keyCode);
        return ucp;
    }

    //电费查询
    public static PowerPackage powerBillCheck(String cusNo) {
        IPowerModule ipm = (IPowerModule)ModuleFactory.GetModule(ModuleName.Power, IP, PORT, SERVICENAME);
        PowerPackage pp = ipm.Query(cusNo, agentNo, clientNo, keyCode);
        return pp;
    }

    //电费缴费
    public static PowerPackage powerPayMoney(String cusNo, Double payMoney, Double perMoney, Double nowMoney, String billSerialno, Double receMoney, Double dueMoney)
    {
        IPowerModule ipm = (IPowerModule)ModuleFactory.GetModule(ModuleName.Power, IP, PORT, SERVICENAME);
        PowerPackage pp = ipm.Payment(cusNo, payMoney, perMoney, nowMoney, billSerialno, receMoney, dueMoney, agentNo, clientNo, PersonNo, keyCode);
        return pp;
    }

    //电费冲正
    public static PowerPackage powerBackOut(String cusNo, String serialNo)
    {
        IPowerModule ipm = (IPowerModule)ModuleFactory.GetModule(ModuleName.Power, IP, PORT, SERVICENAME);
        PowerPackage pp = ipm.BackOut(serialNo, cusNo, agentNo, clientNo, keyCode);
        return pp;
    }

    //公共事业卡查询
    public static UtilitiesPackage utilitiesBillCheck(String cusNo) {
        IUtilitiesModule ium = (IUtilitiesModule)ModuleFactory.GetModule(ModuleName.Utilities, IP, PORT, SERVICENAME);
        UtilitiesPackage up = ium.Query(cusNo, agentNo, clientNo, keyCode);
        return up;
    }

    //公共事业卡缴费
    public static UtilitiesPackage utilitiesPayMoney(String cusNo, Double chargeMoney, Double payMoney)
    { 
        IUtilitiesModule ium = (IUtilitiesModule)ModuleFactory.GetModule(ModuleName.Utilities, IP, PORT, SERVICENAME);
        UtilitiesPackage up = ium.Payment(cusNo, chargeMoney, payMoney, agentNo, clientNo, PersonNo, keyCode);
        return up;
    }

    //公共事业卡冲正
    public static UtilitiesPackage utilitiesBackOut(String cusNo, String serialNo)
    {
        IUtilitiesModule ium = (IUtilitiesModule)ModuleFactory.GetModule(ModuleName.Utilities, IP, PORT, SERVICENAME);
        UtilitiesPackage up = ium.BackOut(serialNo, cusNo, agentNo, clientNo, keyCode);
        return up;
    }

    //公共事业非卡查询
    public static UtilitiesNoCardPackage utilitiesNoCardBillCheck(String cusNo) {
        IUtilitiesNoCardModule iuncm = (IUtilitiesNoCardModule)ModuleFactory.GetModule(ModuleName.UtilitiesNoCard, IP, PORT, SERVICENAME);
        UtilitiesNoCardPackage uncp = iuncm.Query(cusNo, agentNo, clientNo, keyCode);
        return uncp;
    }

    //公共事业非卡缴费
    public static UtilitiesNoCardPackage utilitiesNoCardPayMoney(String defNo, String cusNo, Double payMoney) { 
        IUtilitiesNoCardModule iuncm = (IUtilitiesNoCardModule)ModuleFactory.GetModule(ModuleName.UtilitiesNoCard, IP, PORT, SERVICENAME);
        UtilitiesNoCardPackage uncp = iuncm.Payment(defNo, cusNo, payMoney, agentNo, clientNo, PersonNo, keyCode);
        return uncp;
    }

    //公共事业非卡冲正
    public static UtilitiesNoCardPackage utilitiesNoCardBackOut(String cusNo, String serialNo)
    {
        IUtilitiesNoCardModule iuncm = (IUtilitiesNoCardModule)ModuleFactory.GetModule(ModuleName.UtilitiesNoCard, IP, PORT, SERVICENAME);
        UtilitiesNoCardPackage uncp = iuncm.BackOut(serialNo, cusNo, agentNo, clientNo, keyCode);
        return uncp;
    }

    /*--返回值：	-1：金额总和不对
--			-2：该用户不存在
--			-3：余额不足
--			-4：优惠券不足
--			-999：系统错误*/
    public static String alertExecErroeResult(int result){
        String message;
        switch (result)
        {
            case -1: message = "金额总和不对"; break;
            case -2: message = "用户不存在"; break;
            case -3: message = "余额不足"; break;
            case -4: message = "优惠券不足"; break;
            default: message = "系统错误"; break;
        }
        return message;
    }

    //显示错误信息
    public static String showErrorMessage(String statusNo)
    {

        String message;
        switch(statusNo){                
            //case "00": "成功收发|转账成功"; break;
            case "11": message = "发送失败"; break;
            case "12": message = "接收失败"; break;
            case "13": message = "错误交易,见错误信息."; break;
            case "14": message = "拆包错误"; break;
            case "15": message = "电信返回包为空"; break;
            case "20": message = "无回执,转账验证为成功|转账成功"; break;
            case "23": message = "回执99错误,验证成功.|转账成功"; break;
            case "22": message = "无回执,转账验证通讯失败.|转账通讯异常,请联系财务"; break;
            case "24": message = "回执99错误,验证不成功.|转账通讯异常,请联系财务"; break;
            case "21": message = "扣转查询失败.|转账通讯失败,请稍后再试"; break;
            case "31": message = "账户余额不足!"; break;
            case "32": message = "数据库操作错误!"; break;
            case "33": message = "数据未找到"; break;
            case "51": message = "未经过授权的key"; break;
            case "52": message = "无此商户"; break;
            case "53": message = "无此终端或员工错误"; break;
            case "54": message = "交易暂停,权限不够或未开通模块"; break;
            case "98": message = "其他错误,见错误信息"; break;

            default: message = "未知错误信息，请联系客服！"; break;
        }

        return message;
    
    }

}
